package com.hss.common.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hss.common.R;

/**
 * @author 黄赛赛
 * @version V1.0
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}()
 * @date 2016/5/21 16:05
 */
public class LoadingDialog extends Dialog {

    ImageView iv_loding;
    TextView tv_loading_txt;
    String  msg;
    public LoadingDialog(Context context) {
        this(context, R.style.lodDialog);
    }

    public LoadingDialog(Context context, int themeResId) {
        super(context, themeResId);
        setContentView(R.layout.dialogfragment_loading);

        iv_loding = (ImageView)findViewById(R.id.iv_loding);
        tv_loading_txt = (TextView) findViewById(R.id.tv_loading_txt);
    }


    public  void updateMsg(String msg){
        this.msg = msg;
        if (tv_loading_txt != null){
            tv_loading_txt.setText(this.msg == null ? "" : this.msg);
        }
    }


    @Override
    public void create() {
        super.create();
    }

    @Override
    public void show() {

        if (TextUtils.isEmpty(msg)){
            tv_loading_txt.setVisibility(View.GONE);

        }else {
            tv_loading_txt.setVisibility(View.VISIBLE);
            tv_loading_txt.setText(msg);

        }
        super.show();

    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {

        super.onStart();
        if (iv_loding != null){
            AnimationDrawable animationDrawable = (AnimationDrawable) iv_loding.getDrawable();
            animationDrawable.start();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();

        if (iv_loding != null){
            AnimationDrawable animationDrawable = (AnimationDrawable) iv_loding.getDrawable();
            animationDrawable.stop();
        }
    }
}
